


import bpy
import numpy as np

import 全局控制.Node.节点和插座基类.bl_节点基类 as 基类
from 节点.Core import bl_UI配色

import engine.initLIB.load_dll as engineLib
import ctypes




engineLib.flexCAPI.f_创建vec3矢量计算节点.restype = ctypes.c_bool


E_运算类型枚举_符合名称 = {
	'TYPE_加法':"+",
	'TYPE_减法':"-",
	'TYPE_乘法':"*",
	'TYPE_除法':"/",
	'TYPE_取负':"-!-",
	'TYPE_取余':"%",
	'TYPE_取反':"!",
	'TYPE_左移':"<<",
	'TYPE_右移':">>",

	'TYPE_点积':"dot",
	'TYPE_叉积':"co",
	'TYPE_步进':"setp",

}



def f_update_计算方式(self, context):
	data = list(str(self.m_计算类型))
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));

	if context :
		self.id_data.f_节点数据更新_更新树([self])
		

class C_Node_计算vec3(基类.C_Node_基类):
	bl_dname = 'bl_node_计算vec3'
	bl_label = '计算vec3'

	m_计算类型 = bpy.props.EnumProperty(items=基类.E_运算类型枚举, name="类型", default="TYPE_加法", update=f_update_计算方式)
	def init(self, context):
		super(C_Node_计算vec3, self).f_init(context)

		self.inputs.new('C_Socket_Vec3_Array1D', name='变量A')
		self.inputs.new('C_Socket_Vec3_Array1D', name='变量B')
		self.outputs.new('C_Socket_Vec3_Array1D', name='结果')
		self.f_toCPP(self.id_data)

		self.use_custom_color = True
		self.color = bl_UI配色.g_内部节点颜色
		
	def draw_buttons(self, context, layout):
		layout.prop(self, 'm_计算类型')
	def draw_label(self):
		t = str("变量A " + "*"+ " 变量B")
		return t
	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建vec3矢量计算节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			f_update_计算方式(self, None)
			self.inputs['变量A'].f_update()
			self.inputs['变量B'].f_update()



class C_NODE_MENU_计算vec3(bpy.types.Operator):
	bl_idname = 'node.calculation_vec3'
	bl_label = '计算vec3'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_计算vec3', use_transform=True)
		return {'FINISHED'}

















class C_Node_vec4矢量元素赋值(基类.C_Node_基类):
	bl_dname = 'bl_node_vec4矢量元素赋值'
	bl_label = 'vec4 矢量元素赋值'

	def init(self, context):
		super(C_Node_vec4矢量元素赋值, self).f_init(context)

		self.inputs.new('C_Socket_F32_Array1D', name='值true')
		self.inputs.new('C_Socket_F32_Array1D', name='值false')
		self.inputs.new('C_Socket_I32_Array1D', name='xyzw')
		self.outputs.new('C_Socket_Vec4_Array1D', name='矢量')
		self.f_toCPP(self.id_data)

		self.use_custom_color = True
		self.color = bl_UI配色.g_内部节点颜色
	
	def f_toCPP(self, tree):
		是否更新 = engineLib.flexCAPI.f_创建vec4矢量元素赋值节点(ctypes.c_wchar_p(tree.name), ctypes.c_wchar_p(self.name), self.f_getPyObject(tree));
		if 是否更新 :
			self.inputs['值true'].f_update()
			self.inputs['值false'].f_update()
			self.inputs['xyzw'].f_update()



class C_NODE_MENU_vec4矢量元素赋值(bpy.types.Operator):
	bl_idname = 'node.vec4_element_assignment'
	bl_label = 'vec4 矢量元素赋值'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_vec4矢量元素赋值', use_transform=True)
		return {'FINISHED'}












classes = (
	C_Node_计算vec3,
	C_NODE_MENU_计算vec3,

	C_Node_vec4矢量元素赋值,
	C_NODE_MENU_vec4矢量元素赋值,
)

def register():
	for c in classes:
		bpy.utils.register_class(c)
	#bpy.utils.register_classes_factory(C_物体辅助)

def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)










